<extend name="Public/base" />

<block name="style">
 <link href="__CSS__/freeshipping.min.css?v={:C('CURRENT_FILE_VERSION')}" rel="stylesheet" />
 <link href="__CSS__/mobiscroll.core-2.6.2.css" rel="stylesheet" type="text/css" />
   
<style>
    .page-content{padding:15px 10px;}
    .search_pannl_div .single-col label{width:75px;}
body {
      padding: 0;
      font-family: Helvetica,'é»‘ä½“',Verdana,Arial,Helvetica,sans-serif;
      font-size: 1em;
      background: #eee;
      padding: 0;
      min-width: 320px;
      max-width: 640px;
      margin: 0 auto;
      overflow-x: hidden;
        }
table.tabtr{
            margin-bottom: 10px;
            border:1px solid #ddd;
            font-size: 14px;
            padding:10px;
            width: 100%;
        }
 button#suboffer {
    width: 100px;
    height: 28px;
    margin-left: 10px;
    display: block;
    text-align: center;
    background: #ddd;
    border: 0 none;
    cursor: pointer;
    margin-bottom: 10px;
}  
.weui_panel{ background:none;}   
.tabtr{ background-color:#FFFFFF;}
.module_title{ background-color:#FFFFFF; margin-bottom:10px; font-size:16px; } 
.weui_panel_hd:after { left:0; background-color:#d8d8d8;}
button#suboffer{ margin-left:0; background-color:#5cac25; color:#ffffff;}
.page-content {
    padding: 0px 10px;
}
.asd{ height:30px;}  
button#suboffer{ float:left;}
.txzl{ float:right; line-height:28px;    width: 100px;
    height: 28px;
    margin-right: 10px;
    display: block;
    text-align: center;
    border: 0 none;
    cursor: pointer;
  font-size:12px;
    margin-bottom: 10px;
      background: #5cac25 !important;
    color: #ffffff; }
/*-----cg4tanchu-----*/
.sg_wszl{ width:100%; height:100%; background-color:#000000; background:rgba(0,0,0,.7);position:fixed; z-index:888; top:0; display:none;
 /**  格式，filer: blur(模糊半径)
     *  模糊半径，取值范围0~Npx，0为无效果
     */
/*
 -webkit-filter: blur(10px);
     -moz-filter: blur(10px);
     -o-filter: blur(10px);
     -ms-filter: blur(10px);
     filter: blur(10px);*/}
 .sg_nrk{ width:90%;  position:fixed;  background-color:#FFFFFF; top:-500px; z-index:999; left:50%; margin-left:-44%; padding-bottom:18px;   }
 .sg_nrk_waz{ width:100%;height:38px; background-color:#5cad25; line-height:38px; color:#FFFFFF; font-size:14px; display:block; padding-left:20px; margin-bottom:38px; position:relative;box-sizing:border-box;
-moz-box-sizing:border-box; /* Firefox */
-webkit-box-sizing:border-box; /* Safari */}
 .sg_nrk_waz span{ display:block; position:absolute; width:38px; height:38px; right:0; top:0; cursor:pointer;}
  .sg_nrk_waz span img{ padding:13px;}
 .sg_nrk_waz_xia1{ width:100%; height:32px; display:block;  margin-bottom:8px; }
 .sg_nrk_waz_xia1_wz1{ width:22%; height:32px; line-height:32px; display:block; text-align:right; float:left; font-size:12px !important; color:#000000; padding-right:14px; position:relative;}
 .sg_nrk_waz_xia1_wz1 span{ color:#FF0000; position:absolute; top:4px;}
 .sg_nrk_waz_xia1_wz2{ float:left; width:60%; height:30px; line-height:30px; border:1px solid #cccccc; padding:0 4px;border-radius:2px;
 -moz-box-shadow:0 3px 3px #e5e5e5 inset;              /* For Firefox3.6+ */
-webkit-box-shadow:0 3px 3px #e5e5e5 inset;           /* For Chrome5+, Safari5+ */
  box-shadow:0 3px 3px #e5e5e5 inset;                   /* For Latest Opera */ }

  .lxrcc{ width:138px;}
  .lxrccwz{ width:74px; text-align:center; padding:0;}
  .lxrcc2{ width:370px;}
  .sg_nrk_ccx{ width:186px; height:35px; display:block; margin:auto;}
  .sg_nrk_ccx_a1, .sg_nrk_ccx_a2{ width:90px; height:35px; display:block; line-height:35px; display:block; float:left; font-size:14px; text-align:center; margin-top:20px;}
.sg_nrk_ccx_a1{ margin-right:6px; background-color:#e3e3e5; color:#666666;}
.sg_nrk_ccx_a2{ background-color:#5cad25; color:#FFFFFF;}


 .sg_nrk_waz_xia1_wz2:focus,textarea:focus{border:#4D90FE solid 1px;transition: all .3s ease-in-out;
}
.sg_nrk_waz_xia1_wz3{ width:60%;  height:32px; line-height:32px; display:block; text-align:left; float:left; font-size:12px !important; color:#000000; padding-right:14px;}
.sg_nrk_waz_xia1_wz4{ width:100%; text-align:center; font-size:12px;}

-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
outline:none;box-shadow: 0 0 5px rgba(81, 203, 238, 1);
-webkit-box-shadow: 0 0 5px rgba(81, 203, 238, 1);
-moz-box-shadow: 0 0 5px rgba(81, 203, 238, 1);}
</style>
</block>
<block name="body">
    <div class="weui_panel weui_panel_access">
        <div class="weui_panel_hd module_title">报价单填写</div>
        <div class="weui_panel_bd" id="tablists">
        
<!--             <tr id="tablists">
            <th>商品名</th>
            <th>数量</th>
            <th>报价</th>
            <th>填写数量</th>
            <th>填写报价</th>
             <th>送货时间</th>
             <th>是否批次送货</th>
            </tr> -->
        </div>
        <button id="suboffer">提交报价单</button>
     <div class="txzl" id="activator">完善供应商资料</div>


 <div class="sg_wszl"></div>
  <div class="sg_nrk">
    <div class="sg_nrk_waz" >完善资料<span class="fzccx"><img src="/images/xcc.png"  /></span></div>
          <div class="sg_nrk_waz_xia1">
      <div class="sg_nrk_waz_xia1_wz1" isactive="{$supplier_list.isactive}" id="data_isactive" >资料状态</div>
    
      <if condition="$supplier_list.isactive eq '0'">
        <p class="sg_nrk_waz_xia1_wz3" style="color:red;font-size:12px; ">您的资料正在审核中,请耐心等待......</p>
      <elseif condition="$supplier_list.isactive eq 1"/>
         <p class="sg_nrk_waz_xia1_wz3" style="color:red;font-size:12px;">您的资料已经审核成功！</p>
      <elseif condition="$supplier_list.isactive eq 2"/>
         <p class="sg_nrk_waz_xia1_wz3" style="color:red;font-size:12px;">您的资料审核不合格，请修改资料！</p>
     </if>
     </div>
  <if condition="$supplier_list.isactive eq '1'" >
                 <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">公司名称<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2" name="companyname" readonly="readonly" value="{$supplier_list.companyname}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">ABN<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2" name="abncode"readonly="readonly" value="{$supplier_list.abncode}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">联系人<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="linkname" readonly="readonly" value="{$supplier_list.linkname}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1  ">联系方式<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="moblie" readonly="readonly" value="{$supplier_list.moblie}" />
           </div>
           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">地址<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="address" readonly="readonly" value="{$supplier_list.address }" />
           </div>


           <div class="sg_nrk_waz_xia1">
           <p class="sg_nrk_waz_xia1_wz4" style="color:red;">如果需要修改供应商资料，请联系客服！</p>

           </div>
    <else />
                  <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">公司名称<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2" name="companyname"  value="{$supplier_list.companyname}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">ABN<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2" name="abncode" value="{$supplier_list.abncode}" />
           </div>

           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">联系人<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="linkname" value="{$supplier_list.linkname}" />

             <div class="sg_nrk_waz_xia1_wz1  ">联系方式<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="moblie" value="{$supplier_list.moblie}" />
           </div>
           <div class="sg_nrk_waz_xia1">
             <div class="sg_nrk_waz_xia1_wz1">地址<span>*</span></div>
             <input class="sg_nrk_waz_xia1_wz2 " name="address" value="{$supplier_list.address }" />
           </div>
          <div class="sg_nrk_ccx">
             <div class="sg_nrk_ccx_a1" onclick="close_win()">取消</div>
              <div class="sg_nrk_ccx_a2" onclick="sub_supplier()">保存</div>
             
          </div>
      </if>
 </div>
    </div>

</block>
<block name="script">
    <script src="__JS__/mobiscroll.core-2.6.2.js" type="text/javascript"></script>
    <script src="__JS__/mobiscroll.datetime-2.6.2.js" type="text/javascript"></script>
    <script src="__JS__/mobiscroll.core-2.6.2-zh.js" type="text/javascript"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/js/json2.js"></script>
<script type="text/javascript">
var _time=0;
 var reg=/^\d+(\.\d{0,2})?$/;
 var backurl = AoDaiArr['HTTP_HOST']+"/mobile/user.php?act=supply_list";
 var purchaseid = "{$purchaseid}";
var cookiename="goods_{$purchaseid}";
$(function(){
//读取cookie添加table
//+parseInt(5*Math.random())
debugger;
var _list=getCookie(cookiename);
   if(_list==""){return;}
   var ojson=JSON.parse(_list,true);

    for (var a=0; a<ojson.length; a++) {
      htl =   '<table class="tabtr"><tr><td>商品名:</td><td>'+ojson[a]['goodsname']+'</td></tr><tr><td>数量:</td><td>'+ojson[a]['number']+'</td></tr><tr><td>报价:</td><td>'+ojson[a]['price']+'</td></tr><tr><td>填写数量:</td><td><input  class="inputlist" type="text"  field=\'"listid":"'+ojson[a]['listid']+'","purchaseid":"'+ojson[a]['purchaseid']+'","goodsid":"'+ojson[a]['goodsid']+'","goodsname":"'+ojson[a]['goodsname']+'","price":"'+ojson[a]['price']+'","number":"'+ojson[a]['number']+'","offer_price":"","offer_number":"","sendtime":"","isbatch":""\' name="number" value=""/></td></tr><tr><td>填写报价:</td><td><input type="text" name="price" value=""  /></td></tr><tr> <td>送货时间:</td><td><input type="text" name="test_default" class="test_default" readonly="readonly" value="" /></td></tr><tr><td>是否批次送货:</td><td><select id ="isbatch"><option value="0">否</option><option value="1">是</option></select></td> </tr></table>';
 

   if(htl!=""){
        $("#tablists").append(htl); 
    } 
 }
//日历插件
var curr = new Date().getFullYear();
            var opt = {};
               opt.date = {preset : 'date'};
                opt.default = {
                      //  theme: 'android-holo light', //皮肤样式
                        display: 'modal', //显示方式 
                        mode: 'scroller', //日期选择模式
                        dateFormat: 'yyyy-mm-dd',
                        lang: 'zh',
                        //showNow: true,
                      /*  nowText: "今天",*/
                       // stepMinute: 1,
                        startYear: curr , //开始年份
                        endYear: curr +2//结束年份
                    };
            
$('.test_default').val('').scroller('destroy').scroller($.extend(opt['date'], opt['default']));
   //验证填写的信息
   $('input[type="text"]').bind('keyup',findtable);
     //提交报价单
   $('#suboffer').bind('click',suboffer);
   })

 function  findtable(){
   clearTimeout(_time);
   _this = $(this);
   _time=setTimeout(function(){searchtable(_this);},500);
}

function searchtable(_this){
   if(_this.attr('name') == 'number'){
      var number = _this.val();
      var oldnumber = _this.parent('td').parent('tr').prev().prev().children('td').eq(1).html();
      if(parseInt(number) > parseInt(oldnumber)){
        alert('输入数量大于总数量!');
        _this.val('');
        return ;
      }
      if(!reg.test(number)){
        _this.val('');
        alert('输入数量有误!');
        return ;
      }
    }
     if(_this.attr('name') == 'price'){
      var price = _this.val();
      var oldprice = _this.parent('td').parent('tr').prev().prev().children('td').eq(1).html();
      if(!reg.test(price)){
        _this.val('');
        alert('输入报价有误!');
        return ;
      }
    }
}

   function suboffer(){
     //$(this).attr("disabled","disabled");
     var tablen =  $("table").length ;
     var data = [];
      if(tablen >0 ){
          for(var i=0;i<tablen;i++){
            var _json=$('.tabtr').eq(i).find('tbody').children('tr').eq(3).children('td').eq(1).find('input').attr("field");
            var _json="{"+_json+"}" ;
            var tmp =JSON.parse(_json);
            //alert($('.tabtr').eq(i).find('tbody').children('tr').eq(3).children('td').eq(1).find('input').val());

            var number = $('.tabtr').eq(i).find('tbody').children('tr').eq(3).children('td').eq(1).find('input').val();
            var price = $('.tabtr').eq(i).find('tbody').children('tr').eq(4).children('td').eq(1).find('input').val();
            var sendtime = $('.tabtr').eq(i).find('tbody').children('tr').eq(5).children('td').eq(1).find('input').val();
            if(number == "" || price ==""){
              alert('数量或价格不能为空不能给空!');
              return;
            }
            var isbatch = $('.tabtr').eq(i).find('tbody').children('tr').eq(6).children('td').eq(1).find('select').val();
                      tmp.offer_number = number;
                      tmp.offer_price = price;
                      tmp.sendtime = sendtime;
                      tmp.isbatch = isbatch;
                      if(tmp != ""){
                       data.push(tmp);
                       }
          }
        var _json = JSON.stringify(data);
        saveoffer(_json);
      }
}


   function saveoffer(data){
  debugger;
        //先判断是否有 供应商资料
    var data_isactive =$('#data_isactive').attr('isactive');
     if(data_isactive == ''){
      $("#activator").trigger("click");
      return;
    }

    if(data_isactive == 2){
      alert('亲，供应商资料不合格请继续完善！');
      return;
    }
    if(data_isactive == 0){
      alert('亲，请等待供应商资料审核通过，如果有特殊情况请联系客服！');
       return;
    }
     if(!data){return false;}
     var url="{:U('Offer/add_offer')}";
     $.ajax({
         'url': url,
         'data': {data:data,purchaseid:purchaseid},
         //'dataType': 'json',
         'type': 'POST',
         success: function (data) {
             if(!data){
                alert(data.msg);
                 return;
             }
             if (data.staute =="error") {  
               alert(data.msg);
               return;
             }
             if (data.staute =="success") {  
               setCookie(cookiename,"",-10); //清理cookie信息
               setTimeout(function(){
                   location.replace(backurl);
               },1000)
             }
         }, error: function (err) { 
            alert('网络错误');
         },complete: function () {
            
         }
     });    

   }
//提交供应商资料
function sub_supplier(){
  var companyname = $('input[name=companyname]').val();
  var abncode = $('input[name=abncode]').val();
  var linkname = $('input[name=linkname]').val();
  var moblie = $('input[name=moblie]').val();
  var address = $('input[name=address]').val();
      if($.trim(companyname) =="" || $.trim(abncode) =="" || $.trim(linkname) =="" || $.trim(moblie) =="" || $.trim(address) ==""){
        alert('资料完善不能为空！');
        return;
      }
      var re = /(^0\d{9}$)/;
      if(!re.test(moblie)){
        alert('请填写澳洲号码！');
        return;
      }
        $.ajax({
         'url': "{:U('Offer/set_supplier')}",
         'data': {companyname:companyname,
                   abncode:abncode,
                   linkname:linkname,
                   moblie:moblie,
                   address:address
                 },
         'dataType': 'json',
         'type': 'POST',
        success: function (data) {
        if(data.staute =="success"){

              alert(data.msg);
              close_win();
              return;
        }
        if(data.staute =="error"){
                 alert(data.msg);
              return;
        }  

       }, error: function (err) { 
          alert('网络错误');
       },complete: function () {

       }
});    


}
//读取cookie   
 function getCookie(c_name){
  　　　　if (document.cookie.length>0){　　//先查询cookie是否为空，为空就return ""
  　　　　　　c_start=document.cookie.indexOf(c_name + "=")　　//通过String对象的indexOf()来检查这个cookie是否存在，不存在就为 -1　　
  　　　　　　if (c_start!=-1){ 
  　　　　　　　　c_start=c_start + c_name.length+1　　//最后这个+1其实就是表示"="号啦，这样就获取到了cookie值的开始位置
  　　　　　　　　c_end=document.cookie.indexOf(";",c_start)　　//其实我刚看见indexOf()第二个参数的时候猛然有点晕，后来想起来表示指定的开始索引的位置...这句是为了得到值的结束位置。因为需要考虑是否是最后一项，所以通过";"号是否存在来判断
  　　　　　　　　if (c_end==-1) c_end=document.cookie.length
  　　　　　　　　return unescape(document.cookie.substring(c_start,c_end))　　//通过substring()得到了值。想了解unescape()得先知道escape()是做什么的，都是很重要的基础，想了解的可以搜索下，在文章结尾处也会进行讲解cookie编码细节
  　　　　　　} 
  　　　　}
  　　　　return ""
 }

 function setCookie(c_name, value, expiredays){
    　　　var exdate=new Date();
    　　　exdate.setDate(exdate.getDate() + expiredays);
    　　　document.cookie=c_name+ "=" + escape(value) +";path=/;domain="+document.domain+";"+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
 }

 //关闭弹窗
function close_win(){
      $('.sg_nrk').animate({'top':'-500px' }, 300, function () {

        $('.sg_wszl').fadeOut('300');
      });
}
  /*------弹出滑动窗口--------*/
 $(function () {

        $('#activator').click(function () {

            $('.sg_wszl').fadeIn('300',function () {

                $('.sg_nrk').animate({'top':'50px' }, 300);

            });

        });

        $('.fzccx').click(function () {

            $('.sg_nrk').animate({'top':'-500' }, 300, function () {

                $('.sg_wszl').fadeOut('300');

            });

        });

    });
</script>
</block>


